﻿using System;
using GdNet.Core.Assistants;
using GdNet.WebFramework.Domain.Common;
using GdNet.WebFramework.Domain.ContentManagement;
using GdNet.WebFramework.Domain.ReferencesData;
using GdNet.WebFramework.Domain.Repositories.ContentManagement;
using GdNet.WebFramework.Domain.Repositories.ReferencesData;

namespace GdNet.Applications.DataGeneration.DataAssistants
{
    public static class ContentItemAssistant
    {
        internal static void GenerateSampleContents(IContentItemRepository contentItemRepository, ICatalogRepository catalogRepository)
        {
            var languagesCatalog = catalogRepository.GetByProperty(ObjectAssistant.GetPropertyName<Catalog, string>(c => c.Code), SystemCatalogs.Languages);
            var englishLanguage = languagesCatalog.GetLineByCode(LanguagesCode.English);

            Console.WriteLine("Generating content items...");

            var content1 = ContentItem.Factory.Create("Item 1", true);
            content1.Culture = englishLanguage;

            content1.AddPart(ContentPart.Factory.Create("Part 1", "This is part one", true));
            content1.AddPart(ContentPart.Factory.Create("Part 2", "This is part two", true));

            contentItemRepository.Save(content1);
        }
    }
}
